<!-- 派车列表 -->
<template>
  <div class="dis-order-list">
    <div ref="dgtools" class="filter-container">
      <div class="dgts-fm">
        <el-select v-model="dg.ps.serviceMan" clearable filterable :placeholder="'业务员'" style="width: 90px">
          <el-option v-for="it in serviceManList" :key="it.baseUserId.uname" :label="it.baseUserId.realName"
            :value="it.baseUserId.uname">
          </el-option>
        </el-select>

        <el-select v-model="dg.ps.timeType" :placeholder="'时间类型'" style="width: 100px">
          <el-option :label="'用车时间'" :value="'1'"></el-option>
          <el-option :label="'下单时间'" :value="'2'"></el-option>
          <el-option :label="'续团时间'" :value="'3'"></el-option>
        </el-select>

        <el-date-picker v-model="dg.ps.setime" type="daterange" range-separator="至" start-placeholder="开始日期"
          end-placeholder="结束日期" style="width: 210px" value-format="yyyy-MM-dd">
        </el-date-picker>

        <el-select v-model="dg.ps.compositor" :placeholder="'排序'" style="width: 80px">
          <el-option :label="'升序'" :value="'ASC'"></el-option>
          <el-option :label="'降序'" :value="'DESC'"></el-option>
        </el-select>

        <el-input style="width: 140px" placeholder="订单号" v-model="dg.ps.orderNum">
        </el-input>

        <el-input style="width: 220px" placeholder="行程详情/客户/驾驶员/业务员备注" v-model="dg.ps.routeDetail">
        </el-input>

        <el-select v-model="dg.ps.orderStatus" multiple collapse-tags :placeholder="'订单状态'" style="width: 180px">
          <el-option v-for="it in orderStates" :label="it.name" :key="it.id" :value="it.id">
          </el-option>
        </el-select>

        <el-select v-model="dg.ps.serviceType" :placeholder="'业务类型'" style="width: 150px">
          <el-option v-for="it in serviceTypes" :key="it.val" :label="it.label" :value="it.val">
          </el-option>
        </el-select>

        <el-input style="width: 80px" placeholder="座位数" maxlength="2"
          onkeyup="this.value = this.value.replace(/^(0+)|[^\d]+/g, '');" v-model="dg.ps.seats">
        </el-input>

        <el-input style="width: 100px" placeholder="车牌号" maxlength="8" v-model="dg.ps.plateNum">
        </el-input>

        <el-input style="width: 130px" placeholder="驾驶员姓名/手机号" maxlength="11" v-model="dg.ps.driver">
        </el-input>

        <template v-if="dg.ftState">
          <el-select v-model="dg.ps.customId" clearable filterable :remote="true" :remote-method="queryCusPageList"
            :placeholder="'请搜索选择用车单位'" style="width: 150px">
            <el-option v-for="it in clientList" :key="it.baseUserId.id"
              :label="it.baseUserId.realName + '【' + it.baseUserId.phone + '】【' + it.unitName + '】'" :value="it.id"
              @click.native="selectCus(it.baseUserId.uname)"></el-option>
          </el-select>

          <el-select v-model="dg.ps.dutyMan" clearable filterable :placeholder="'联系人'" style="width: 140px">
            <el-option v-for="it in dutyManList" :key="it.uname" :label="it.realName" :value="it.uname">
            </el-option>
          </el-select>

          <el-select v-model="dg.ps.useSelf" :placeholder="'是否自营'" style="width: 140px">
            <el-option :label="'是否自营（全部）'" :value="''"></el-option>
            <el-option :label="'已外调'" :value="0"></el-option>
            <el-option :label="'已自营'" :value="1"></el-option>
            <el-option :label="'需自营'" :value="2"></el-option>
          </el-select>

          <el-select v-model="dg.ps.suppCusId" clearable filterable :placeholder="'供车方单位'" style="width: 140px">
            <el-option v-for="it in suppCarComList" :key="it.baseUserId.uname"
              :label="it.unitName + '（' + it.baseUserId.realName + '）'" :value="it.id"
              @click.native="selectSuppCarCom(it)">
              <span style="float: left">{{ it.unitName }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ it.baseUserId.realName }}</span>
            </el-option>
          </el-select>

          <el-select v-model="dg.ps.suppMan" clearable filterable :placeholder="'供车方负责人'" style="width: 140px">
            <el-option v-for="it in suppCarDutyManList" :key="it.uname" :label="it.realName" :value="it.uname">
              <span style="float: left">{{ it.realName }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ it.phone }}</span>
            </el-option>
          </el-select>
        </template>

        <ShMoreFt :dgName="dg.dgName" @myclick="onShMoreFt"></ShMoreFt>
      </div>

      <div style="">
        <el-button type="primary" icon="el-icon-search" @click="getDgList">搜索</el-button>

        <!-- <el-button 
          type="primary" 
          icon="el-icon-bell" 
          @click="noticeDriver"
        >通知师傅</el-button> -->

        <el-button type="primary" icon="el-icon-edit" @click="editChildOrder">修改订单</el-button>

        <el-button type="primary" icon="el-icon-delete" @click="delChildOrder">删除订单</el-button>

        <el-button type="primary" icon="el-icon-document-delete" @click="cancelDisOrder">取消派车</el-button>

        <el-button type="primary" icon="el-icon-money" @click="payInternetFeeMd(true)">付上网费</el-button>

        <el-button type="primary" icon="el-icon-document-copy" @click="copyChildOrder"
          title="在所选订单父级下新增订单">复制订单</el-button>

        <el-button type="primary" icon="el-icon-menu" @click="splitOrderMd({ state: true })">拆分订单</el-button>

        <!-- <el-button
          type="primary"
          icon="el-icon-money"
          @click="collectInternetFeeMd(true)"
        >收上网费</el-button>

        <el-button 
          type="primary" 
          icon="el-icon-s-tools" 
          @click="setOutTransfer"
        >设为外调</el-button> -->

        <el-button type="primary" icon="el-icon-time" @click="emptyTimesMd({ state: true })">临空设置</el-button>

        <el-button type="primary" icon="el-icon-right" @click="setTransferSfcOrderMd({ state: true })">
          转顺风车
        </el-button>

        <el-button type="primary" icon="el-icon-close" @click="cancelTransferSfcOrder">
          取消转顺风车
        </el-button>

        <el-button :type="dg.ps.unionOrder === 0 ? 'success' : 'warning'"
          :icon="dg.ps.unionOrder === 0 ? 'el-icon-tickets' : 'el-icon-close'" @click="queryUnionOrder">
          {{ dg.ps.unionOrder === 0 ? '查询联盟订单' : '取消查询联盟订单' }}
        </el-button>

        <el-button type="success" icon="el-icon-s-tools" @click="$event => setUnionOrder(1)">
          设置联盟订单
        </el-button>

        <el-button type="warning" icon="el-icon-close" @click="$event => setUnionOrder(0)">
          取消设置联盟订单
        </el-button>

        <el-button type="warning" icon="el-icon-folder-opened" @click="mergeOrdersFlag(1)">
          合并订单
        </el-button>

        <el-button type="warning" icon="el-icon-folder-opened" @click="mergeOrdersFlag(0)">
          取消合并订单
        </el-button>
        <el-button type="warning" icon="el-icon-full-screen" @click="QRcodeBtn()">
          代收二维码
        </el-button>
        <el-button type="warning" icon="el-icon-position" @click="isUseDidi_btn">
          滴滴打车订单设置
        </el-button>
        <!-- 上传代收二维码 -->
        <el-dialog title="上传代收二维码与代收金额" :visible.sync="QRcode" width="30%">
          <div style="display: flex;    justify-content: space-evenly;">
            <div>
              代收二维码:
              <UploadImg style="width: 200px;height:200px;line-height: 200px;overflow: hidden;" :imgName="'dg'"
                @getImgUrl="setImgUrl" :url="'/company/upload'" :ps="{ userName: uname }"
                :src="fileBaseUrl + dg.ps.imgUrl" :tiptext="''" />
            </div>
            <div>
              代收金额:
              <el-input type="number" placeholder="请输入金额" v-model="dg.ps.helpGathPrice" clearable>
              </el-input>
            </div>
          </div>

          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="addQRcodeBtn()">确 定</el-button>
          </span>
        </el-dialog>

        <!-- 滴滴打车订单设置 -->
        <el-dialog title="滴滴打车订单设置" :visible.sync="isUseDidi_off" width="30%">
          <div>
            <div> 设置值:
              <el-switch v-model="isUseDidi_value" active-color="#13ce66" inactive-color="#DCDFE6">
              </el-switch>
            </div>

          </div>

          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="isUseDidi_ok">确 定</el-button>
          </span>
        </el-dialog>


      </div>

      <TableSelfSet v-if="dg.columns.length > 0" :tbTitle="'派单列表'" :dgName="dg.dgName" :tbId="dg.tbName"
        :srcCols="dg.srcCols" :columns="dg.columns" @saveSet="saveTbSet" />
    </div>

    <el-table :ref="dg.tbName" :data="dg.list" row-key="id" :height="bodyHeight" border fit :row-class-name="rowClassName"
      @header-dragend="dragHeader" @selection-change="selRowChange" :header-cell-style="headerStyle"
      :cell-style="cellStyle" :row-style="rowStyle">

      <el-table-column fixed="left" type="index" label="编号" width="40"></el-table-column>
      <el-table-column fixed="left" type="selection" width="40"></el-table-column>
      <el-table-column v-for="(col, index) in dg.columns" :key="index" :class-name="dg.dgName" :prop="col.field"
        :label="col.label" :width="col.width">

        <template slot-scope="{row}">



          <template v-if="col.field == 'status'">
            <span v-if="row.status.val == 'NOT_DIS_CAR'">
              <span v-if="row.freeMark">顺风</span>
              <span v-else-if="row.transferMark">转接</span>
              未派车
              <template v-if="!row.freeMark">
                <el-button type="primary" @click.native="disCarMd({ state: true, obj: row })">派车</el-button>
              </template>
            </span>
            <span v-else-if="row.status.val == 'JL_NOT_CONFIRM'">未通知 <el-button type="primary"
                @click.native="noticeDriver(row)">通知</el-button></span>
            <span v-else-if="row.status.val == 'DRIVER_NOT_CONFIRM'">已通知</span>
            <span v-else>{{ row.status.label }}</span>
          </template>

          <template v-else-if="col.field == 'plateNum'">
            <span>{{ row.plateNum }}</span>
            <el-button v-if="row.plateNum" type="primary" @click.native="setUpdOrderCarMd({ state: true, row: row })">
              修改车辆
            </el-button>
          </template>
          <!-- 合并标记 -->
          <template v-else-if="col.field == 'mergeOrdersFlag'">
            <span>{{ row.mergeMark }}</span>

          </template>
          <!-- 车型 -->
          <template v-else-if="col.field == 'needSeats'">
            <span>{{ row.needSeats }}</span>

          </template>
          <!-- 异常报备 -->
          <template v-else-if="col.field == 'accidentRecord'">
            <el-button @click.native="accidentRecord_btn(row)" v-if="row.accidentRecord" type="primary">
              异常报备
            </el-button>
            <span v-else>无</span>
          </template>


          <template v-else-if="col.field == 'driver'">
            <div v-if="!row.driver">
              <el-button v-if="row.status.val != 'NOT_DIS_CAR' && row.status.val != 'NOT_DIS_CAR'" type="primary"
                @click.native="setSetMainDriverMd({ state: true, row: row })">
                设置驾驶员
              </el-button>
            </div>
            <div v-else>
              <span>{{ row.driver }}</span><br />
              <el-button type="primary" @click.native="setSetMainDriverMd({ state: true, row: row })">
                修改驾驶员
              </el-button>
            </div>
          </template>

          <span v-else-if="col.field == 'sdate'">{{ row.stime.split(" ")[0] }}</span>

          <span v-else-if="col.field == 'stime'">{{ row.stime.substr(11, 5) }}</span>

          <span v-else-if="col.field == 'edate'">{{ row.etime.split(" ")[0] }}</span>

          <span v-else-if="col.field == 'etime'">{{ row.etime.substr(11, 5) }}</span>

          <template v-else-if="col.field == 'routeDetail'">
            <span v-html="row.routeDetail.replace(/@/g, '<br />')"></span>
          </template>

          <span v-else-if="col.field == 'cusNote'">{{ row.cusNote }}</span>

          <span v-else-if="col.field == 'driverNote'">{{ row.driverNote }}</span>

          <span v-else-if="col.field == 'serviceNote'">{{ row.serviceNote }}</span>

          <template v-else-if="col.field == 'companyName'">
            {{ row.companyName.split("=")[1] }}-{{ row.companyName.split("=")[2] }}
          </template>

          <template v-else-if="col.field == 'dutyBaseUser'">
            {{ row.dutyBaseUser.split("=")[1] }}-{{ row.dutyBaseUser.split("=")[2] }}
          </template>

          <template v-else-if="col.field == 'serviceManName'">
            {{ row.serviceManName.split("-")[1] }}
          </template>

          <span v-else-if="col.field == 'addTime'">{{ row.addTime.substr(0, 16) }}</span>

          <template v-else>{{ getColVal(row, col.field) }}</template>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="dg.total > 0" :total="dg.total" :page.sync="dg.ps.page" :limit.sync="dg.ps.rows"
      @pagination="getDgList" :left="true">
      <template #default>
        <label class="c-black">已派总数：<span>{{ tj.carCount }}辆</span></label>
        <el-divider direction="vertical"></el-divider>

        <label class="c-black">订单总价：<span>{{ tj.totalPrice }}元</span></label>
        <el-divider direction="vertical"></el-divider>

        <label>未派车：<span>{{ tj.noCar }}条</span></label>
        <el-divider direction="vertical"></el-divider>

        <label :style="{ 'color': '#f00' }">未定价：<span>{{ tj.noPrice }}条</span></label>
        <el-divider direction="vertical"></el-divider>

        <label :style="{ 'color': '#FBAEAA' }">未通知：<span>{{ tj.jlNotConfirm }}条</span></label>
        <el-divider direction="vertical"></el-divider>

        <label :style="{ 'color': '#a9befd' }">已通知：<span>{{ tj.driverNotConfirm }}辆</span></label>
        <el-divider direction="vertical"></el-divider>

        <label :style="{ 'color': '#045155' }">已确认：<span>{{ tj.driverConfirm }}辆</span></label>
        <el-divider direction="vertical"></el-divider>

        <label :style="{ 'color': '#a1d28a' }">运行中：<span>{{ tj.travel }}辆</span></label>
        <el-divider direction="vertical"></el-divider>

        <label :style="{ 'color': '#ffbebe' }">已完团：<span>{{ tj.complete }}条</span></label>
      </template>
    </Pagination>

    <AddBusinessLeader v-if="md.addBL.state" :state="md.addBL.state" :data="md.addBL.data"
      @getMdState="getAddBLMdState" />

    <AddCus v-if="md.add.state" :state="md.add.state" @getMdState="getAddMdState" @reloadDg="getDgList" />

    <UpdCus v-if="md.upd.state" :state="md.upd.state" :data="md.upd.data" @getMdState="getUpdMdState"
      @reloadDg="getDgList" />

    <UpdOrder v-if="md.updOrder.state" :state="md.updOrder.state" :order="md.updOrder.order"
      :allServiceManList="serviceManList" @getMdState="updOrderMdState" @reloadDg="getDgList" />

    <AddMainDriver v-if="setMainDriverMd.state" :mdTitle="'设置-订单驾驶员'" :myData="setMainDriverMd"
      @myClick="setSetMainDriverMd" />

    <PayInternetFee v-if="md.payInternetFee.state" :myData="md.payInternetFee" @myClick="payInternetFeeMd" />

    <CollectInternetFee v-if="md.collectInternetFee.state" :myData="md.collectInternetFee" @myClick="collectInternetFeeMd"
      @reloadDg="getDgList" />

    <DisCar v-if="md.disCar.state" :myData="md.disCar" @myClick="disCarMd" @reloadDg="getDgList" />

    <SplitOrder v-if="md.splitOrder.state" :myData="md.splitOrder" @myClick="splitOrderMd" @reloadDg="getDgList" />

    <EmptyTimes v-if="md.emptyTimes.state" :myData="md.emptyTimes" @getMdState="emptyTimesMd" @reloadDg="getDgList" />

    <TransferSfcOrder v-if="transferSfcOrderMd.state" :myData="transferSfcOrderMd" @myClick="setTransferSfcOrderMd"
      @reloadDg="getDgList" />

    <UpdOrderCar v-if="updOrderCarMd.state" :mdTitle="'修改-订单车辆'" :myData="updOrderCarMd" @myClick="setUpdOrderCarMd"
      @reloadDg="getDgList" />

    <!-- 异常报备弹窗 -->
    <!-- :row-style="{ height: '30px' }" -->
    <el-dialog width="90%" title="异常报备" :visible.sync="accidentRecord_off">
      <el-table size="medium" border height="500" :row-style="{ height: '100px' }" :header-cell-style="{ height: '35px' }"
        :data="accidentRecord_list">
        <el-table-column property="accidentName" label="报备名称" height="50" width="180"></el-table-column>
        <el-table-column property="accidentContent" label="报备内容" width="200"></el-table-column>
        <el-table-column property="accidentNote" label="报备备注"></el-table-column>
        <el-table-column property="addTime" label="报备时间" width="180"></el-table-column>
        <el-table-column label="报备图片" width="120">
          <template slot-scope="scope">


            <el-image :preview-src-list="['https://cba360.com/kcbFiles' + scope.row.accidentUrl]"
              v-if="scope.row.accidentUrl" style="width: 100px; height: 100px"
              :src="'https://cba360.com/kcbFiles' + scope.row.accidentUrl" fit="cover"></el-image>
            <p v-else style="text-align: center;">无</p>

          </template>
        </el-table-column>
        <el-table-column label="调度异常处理">
          <template slot-scope="scope">

            <el-button v-if="scope.row.serviceDisposeContent == '未处理'" type="danger"
              @click.native="disposeAccident_btn(scope)">
              未处理
            </el-button>
            <div v-if="scope.row.serviceDisposeContent != '未处理'">内容:{{ scope.row.serviceDisposeContent }}</div>
            <div v-if="scope.row.serviceDisposeContent != '未处理'">时间:<span style="color: red;">{{
              scope.row.serviceDisposeTime }}</span>
            </div>
            <el-button v-if="scope.row.serviceDisposeContent != '未处理'" type="success"
              @click.native="disposeAccident_btn(scope)">
              修改
            </el-button>


          </template>
        </el-table-column>
        <el-table-column label="旅行社异常处理">
          <template slot-scope="scope">

            <div style="color: red;" v-if="scope.row.travelDisposeContent == '未处理'">
              未处理
            </div>
            <div v-if="scope.row.travelDisposeContent != '未处理'">内容:{{ scope.row.travelDisposeContent }}</div>
            <div v-if="scope.row.travelDisposeContent != '未处理'">时间:<span style="color: red;">{{
              scope.row.travelDisposeTime }}</span>
            </div>
            <!-- <el-button v-else-if="scope.row.travelDisposeContent != '未处理'" type="success"
              @click.native="travelDisposeContent_btn(scope)">
              已处理
            </el-button> -->


          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 异常处理 -->
    <el-dialog title="处理异常报备" :visible.sync="disposeAccident_off" width="430px">
      <el-input type="textarea" autosize placeholder="请输入内容" v-model="disposeAccidentContent">
      </el-input>

      <!-- <div v-if="disposeAccidentContent != '未处理'" style="font-weight:700;margin-top: 10px; ">处理时间：<span
          style="font-weight: 700;color:red">{{
            disposeAccident.serviceDisposeTime
          }}</span></div> -->


      <span slot="footer" class="dialog-footer">
        <el-button @click="disposeAccident_off = false">取 消</el-button>
        <el-button type="primary" @click="disposeAccident_data">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="旅行异常处理" :visible.sync="travelDisposeContent_off" width="430px">
      <div>
        <div style="font-weight: 700;">处理内容：{{ travelDisposeContent.disposeAccidentContent }}</div>
        <div style="font-weight: 700;margin-top: 10px;margin-bottom:40px">处理时间：<texe style="font-weight: 700;color:red;">
            {{ travelDisposeContent.serviceDisposeTime }}</texe>
        </div>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { Message, Switch } from "element-ui";

import { mapGetters } from "vuex";
import DataGridBase from "@/views/mixins/DataGridBase";
import DataGridResize from "@/views/mixins/DataGridResize";
import elDragDialog from "@/directive/el-drag-dialog";
import TableSelfSet from "@/components/TableSelfSet";
import Pagination from "@/components/Pagination";

import * as orderService from "@/api/services/order.service";
import * as cusService from "@/api/services/cus.service";
import * as commService from "@/api/services/common.service";
import * as logisticsSer from "@/api/services/logistics.service";

import ShMoreFt from '@/components/ShMoreFt';
import DisCar from "../order-list/components/DisCar";
import AddBusinessLeader from "../add-business-leader";
import UpdOrder from "../order-list/upd-order";
import PayInternetFee from "./pay-internet-fee";
import CollectInternetFee from "./collect-internet-fee";
import SplitOrder from "./split-order";
import EmptyTimes from './EmptyTimes';
import UpdOrderCar from './upd-order-car';
import AddMainDriver from "@/views/logistics-man/car-list/add-mian-driver";
import TransferSfcOrder from './transfer-sfc-order';
import UploadImg from "@/components/UploadImg";

import { getToken } from '@/utils/auth';
export default {
  name: "DisorderList",
  mixins: [DataGridBase, DataGridResize],
  directives: { elDragDialog },
  components: {
    ShMoreFt,
    TableSelfSet,
    Pagination,
    AddBusinessLeader,
    DisCar,
    UpdOrder,
    PayInternetFee,
    CollectInternetFee,
    SplitOrder,
    EmptyTimes,
    AddMainDriver,
    TransferSfcOrder,
    UpdOrderCar,
    UploadImg,
    ElSwitch: Switch,
  },
  data() {
    let cols = [
      { label: '行程简称', field: 'routeSimpleName', width: 150 },
      { label: "订单状态", field: "status", width: 100 },
      { label: "已派车辆", field: "plateNum", width: 85 },
      { label: "车型", field: "needSeats", width: 60 },
      { label: "台数", field: "needCars", width: 60 },
      { label: "人数", field: "customers", width: 60 },
      { label: "航班/车次号", field: "flightOrTrainNum", width: 80 },
      { label: "驾驶员", field: "driver", width: 85 },
      { label: "出发日期", field: "sdate", width: 85 },
      { label: "出发时间", field: "stime", width: 70 },
      { label: "到达日期", field: "edate", width: 85 },
      { label: "到达时间", field: "etime", width: 70 },
      { label: "行程详情", field: "routeDetail", width: 550 },
      { label: "客户备注", field: "cusNote", width: 250 },
      { label: "驾驶员备注", field: "driverNote", width: 250 },
      { label: "业务员备注", field: "serviceNote", width: 250 },
      { label: "用车单位", field: "companyName", width: 85 },
      { label: "联系人", field: "dutyBaseUser", width: 85 },
      { label: "业务员", field: "serviceManName", width: 65 },
      { label: "订单价格", field: "price", width: 70 },
      // { label: "已收金额", field: "alGathPrice", width: 70 },
      { label: "旅网金额", field: "travelPrepayPrice", width: 70 },
      { label: "自网金额", field: "selfPrepayPrice", width: 70 },
      { label: '是否自营', field: 'isExternalName', width: 80 },
      { label: "订单号", field: "orderNum", width: 60 },
      { label: "行程联系人", field: "routeLink", width: 60 },
      { label: "业务类型", field: "serviceType", width: 80 },
      { label: "添加时间", field: "addTime", width: 70 },
      { label: "合并标记", field: "mergeOrdersFlag", width: 70 },
      { label: "异常报备", field: "accidentRecord", width: 70 },
    ];

    return {
      isUseDidi_value: false,// 滴滴打车数据
      isUseDidi_off: false, // 滴滴打车设置
      orderNum: "",
      disposeAccidentContent: "",
      disposeAccident_list: {},
      disposeAccident: {
        accidentIndex: "",
        disposeAccidentContent: "",
        orderNum: "",
        serviceDisposeTime: "",
      },// 异常处理内容
      travelDisposeContent_off: false, // 旅游异常处理
      travelDisposeContent: {
        disposeAccidentContent: "",
        serviceDisposeTime: "",
      },

      disposeAccident_off: false,// 异常处理弹窗
      accidentRecord_list: [],//异常报备列表
      accidentRecord_off: false,//异常报备弹窗
      helpGathPrice: '',// 代收金额
      helpGathUrl: '',// 已有的代收二维码
      headers: { "X-Token": getToken() },
      fileBaseUrl: this.C.fileBaseUrl,  // 文件地址前缀
      QRcode: false,// 代收二维码
      resDgList: [], // 原table列表数据（为了复制主订单功能）
      dg: {
        // 数据列表参数
        dgName: "dg",
        tbName: "disOrderListTb",
        total: 0,
        list: [],
        srcCols: cols,
        columns: [],
        selRows: [],
        ftState: false,
        ps: {
          // 过滤参数
          page: 1,
          rows: 100,
          /**业务员 */
          serviceMan: "",
          /**用车时间 */
          timeType: "1",
          /**排序 */
          compositor: "ASC",
          /**时间 */
          setime: [],
          /**订单号 */
          orderNum: "",
          /**行程详情 */
          routeDetail: "",
          /**订单状态 */
          orderStatus: [],
          /**业务类型 */
          serviceType: "",
          /**座位数 */
          seats: "",
          /**车牌号 */
          plateNum: "",
          /**驾驶员（手机/姓名） */
          driver: "",
          /**用车单位 */
          customId: "",
          /**联系人 */
          dutyMan: "",
          /**是否自营 */
          useSelf: "",
          /** 供车方单位 */
          suppCusId: "",
          /** 供车方负责人 */
          suppMan: "",
          /**订单来源 */
          orderSource: "",
          /** 联盟订单 */
          unionOrder: 0,
          // 图片url
          imgUrl: '',
          // 代收金额
          helpGathPrice: '',
          // 异常报备
          accidentRecord: '',
        },
      },
      // 数据统计
      tj: {
        // 车辆总数
        carCount: "0",
        // 订单总价
        totalPrice: "0",
        // 未派车
        noCar: '0',
        // 未定价
        noPrice: '0',
        // 未通知
        jlNotConfirm: '0',
        // 已通知
        driverNotConfirm: '0',
        // 已确认
        driverConfirm: '0',
        // 运行中
        travel: '0',
        // 已完团
        complete: '0',
      },
      md: {
        // 弹框数据
        addBL: { state: false },
        add: { state: false },
        upd: { state: false },
        // // 添加订单-弹框
        // addOrder: { state: false, order: null },
        // 修改订单-弹框
        updOrder: { state: false, order: null },
        // 线上派车-弹框
        disCar: { state: false },
        // 付上网费-弹框
        payInternetFee: { state: false },
        // 收上网费-弹框
        collectInternetFee: { state: false },
        // 拆分订单-弹框
        splitOrder: { state: false },
        // 临空时间设置-弹框
        emptyTimes: {
          state: false,   // 开关状态
          orderNum: '',   // 要设置的订单编号
          date: null,     // 出发日期
          stime: null,    // 开始时间
          etime: null,    // 结束时间
          posList: [],    // 当天行程所有地点数组
          emptyTimes: [], // 默认临空时间数组
        },
      },

      // 设置车辆-弹框
      updOrderCarMd: { state: false },
      // 设置主驾-弹框
      setMainDriverMd: { state: false },
      // 转顺风车订单-弹框
      transferSfcOrderMd: { state: false },

      serviceTypes: [
        // 业务类型
        { val: "", label: "业务类型（全部）" },
        { val: "COUNTY_SER", label: "县际业务" },
        { val: "CITY_SER", label: "市际业务" },
        { val: "PROVINCE_SER", label: "省际业务" },
      ],
      orderStates: [
        // 订单状态数组
        { id: "", name: "订单状态（全部）" },
        { id: "NOT_DIS_CAR", name: "未派车" },
        { id: "JL_NOT_CONFIRM", name: "未通知" },
        { id: "DRIVER_NOT_CONFIRM", name: "已通知" },
        { id: "DRIVER_CONFIRMED", name: "师傅已确认" },
        { id: "AL_TRAVEL", name: "已出行" },
        { id: "COMPLETED", name: "已完成" },
        { id: "PENDING", name: "已待定" },
        { id: "CANCELED", name: "已取消" },
        { id: "REFUSED", name: "已拒绝" },
        { id: "GRAB_SUCCESS", name: "抢单成功" },
        { id: "TRANS_SUCCESS", name: "转接成功" },
        { id: "START_TAKE_CUS", name: "出发去接客户" },
      ],
      orderFromArr: [
        // 订单来源数组
        { id: "PC_COMPANY", name: "电脑端-单位" },
        { id: "PC_PERSONAL", name: "电脑端-个人" },
        { id: "MOBILE_COMPANY", name: "移动端-单位" },
        { id: "MOBILE_PERSONAL", name: "移动端-个人" },
      ],
      serviceManList: [], // 业务员数据列表
      clientList: [], // 客户数据列表
      dutyManList: [], // 联系人数据列表
      suppCarComList: [], // 供车方单位列表
      suppCarDutyManList: [], // 供车方负责人列表
    };
  },
  created() {
    const that = this;

    // 定义搜索时间默认，开始时间为当前日期，结束时间为开始日期后1天
    if (that.dg.ps.setime.length == 0) {
      that.dg.ps.setime.push(that.U.date2str(new Date(), 'yyyy-MM-dd'));
      that.dg.ps.setime.push(that.U.date2str(new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 1), 'yyyy-MM-dd'));
    }


    that.initTbSetData(that.dg.dgName);
    that.getDgList();

    that.getCompanyAllSalesman();
    // that.cusUnameList();
    that.getSuppCarComList();
  },
  computed: {
    ...mapGetters(["uname"]),
  },
  mounted() {
    let that = this
    setTimeout(() => {
      that.initTbSetData(that.dg.dgName);
    }, 1000);
   
  },
  methods: {
    // 滴滴打车设置
    isUseDidi_btn() {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length < 1 || rows.length < 1) {
        U.qerror('必须选择一条订单');
      } else {
        that.isUseDidi_value = rows[0].isUseDidi == 1 ? true : false
        that.isUseDidi_off = true
      }

    },
    isUseDidi_ok() {
      const that = this, U = that.U, rows = that.getSeledRows();
      let ids = []
      for (let i = 0; i < rows.length; i++) {
        ids.push(rows[i].id)
      }
      let ps = {
        ids: ids.join(','),
        isUseDidi: that.isUseDidi_value ? '1' : '0'
      }
      orderService.isUseDidi(ps).then((res) => {
        if (!res || res.code != 1) {
          U.qerror(res.msg);
        } else {
          that.getDgList()
          U.qsuccess(res.msg);
        }
      });

      that.isUseDidi_off = false
    },
    travelDisposeContent_btn(e) {
      this.travelDisposeContent_off = true
      console.log(e)
      this.travelDisposeContent.disposeAccidentContent = e.row.travelDisposeContent
      this.travelDisposeContent.serviceDisposeTime = e.row.travelDisposeTime


    },
    // 异常处理
    disposeAccident_btn(e) {
      console.log(e)
      let that = this, U = that.U, C = that.C;
      let date = new Date()
      let y = date.getFullYear()
      let m = date.getMonth()
      let d = date.getDate();
      m = (m > 9) ? m : ("0" + m);
      d = (d < 10) ? ("0" + d) : d;
      // 出发时间：默认当前时间点
      // // 时间
      let hours = date.getHours();
      let minutes = date.getMinutes();
      minutes = minutes < 10 ? '0' + minutes : minutes;
      let seconds = date.getSeconds();
      seconds = seconds < 10 ? '0' + seconds : seconds;
      let inTime = hours + ':' + minutes + ':' + seconds;
      let time = y + '-' + m + '-' + d + ' ' + inTime

      that.disposeAccident_off = true
      that.disposeAccident_list = {
        accidentIndex: e.row.accidentIndex,
        orderNum: that.disposeAccident.orderNum,
        serviceDisposeTime: time,
      }
      that.disposeAccidentContent = e.row.serviceDisposeContent
      that.disposeAccident.serviceDisposeTime = e.row.serviceDisposeTime
      console.log(e, 'that.disposeAccident_list')

    },
    disposeAccident_data() {
      let that = this, U = that.U;

      that.disposeAccident_list.disposeAccidentContent = that.disposeAccidentContent
      let ps = that.disposeAccident_list
      orderService.disposeAccident(ps).then((res) => {
        if (!res || res.code != 1) {
          U.qerror(res.msg);
        } else {
          that.getDgList()
          that.disposeAccident_off = false
          that.accidentRecord_off = false
        }
      });
    },

    // 异常报备
    accidentRecord_btn(e) {
      this.accidentRecord_off = true
      console.log(e)

      this.accidentRecord_list = e.accidentRecord
      this.disposeAccident.orderNum = e.orderNum
      // this.disposeAccidentContent = e.accidentRecord.travelDisposeContent
    },


    /**
       * 设置-图片url
       * @param e 上传成功后的服务器图片url
       */
    setImgUrl(e) {
      this[e.name].ps.imgUrl = e.url;
    },



    /**
     * 获取-单位客户列表（用于下拉框）
     * @param find 客户手机号/用户名/姓名
     */
    queryCusPageList(find) {
      const that = this;

      commService.queryComboCusPageList({ page: 1, rows: 20, find: find }).then(res => {
        if (res && res.code == 1) that.clientList = res.data;
      });
    },
    /**
     * 处理列表数据（将线性数据处理为树形数据）
     * @param list 欲处理的数据
     */
    filterDgList(list) {
      const that = this;

      let resList = [], pageTotalPrice = 0;
      list.forEach((it, i) => {
        pageTotalPrice += parseFloat(it.price);

        // 主订单状态-描述
        let cstatusObj = that.orderStates.find((os) => { return it.status == os.id; });
        // 驾驶员信息
        let driver = "";
        if (it.disCarId) {
          if (it.disCarId.mainDriver) {
            driver = it.disCarId.mainDriver.uname + "=" + it.disCarId.mainDriver.realName + "=" + it.disCarId.mainDriver.phone;
          } else if (it.disCarId.outDriverInfo) {
            driver = it.disCarId.outDriverInfo + "=" + it.disCarId.outDriverInfo.split(',')[1] + "=" + it.disCarId.outDriverInfo.split(',')[0];
          }
        }

        // 业务类型
        let serviceType = that.serviceTypes.find((o) => { return it.serviceType == o.val; });

        // 航班/车次号累加
        let flightOrTrainNumArr = [];
        it.dayMps?.forEach(fn => {
          if (fn.routeStationInfo) flightOrTrainNumArr.push(fn.routeStationInfo.num);
        });

        // 组装-单条数据
        let obj = {
          dgName: it.dgName,
          id: it.id,
          // 订单号
          orderNum: it.orderNum,
          // 主订单编号
          mainOrderNum: it.mainOrderNum,
          // 行程简称
          routeSimpleName: it.routeSimpleName,
          // 订单状态
          status: { val: it.status, label: cstatusObj ? cstatusObj.name : "" },
          // 顺风车订单标记
          freeMark: it.freeMark,
          // 转接订单标记
          transferMark: it.transferMark,
          // 派单车辆：车牌号
          plateNum: it.disCarId ? it.disCarId.plateNum : "",
          // 需求座位数
          needSeats: it.needSeats,
          // 人数
          customers: it.customers,
          // 航班号
          flightOrTrainNum: flightOrTrainNumArr.join(','),
          // 需求车辆数
          needCars: 1,
          // 驾驶员：驾驶员用户名=驾驶员姓名=驾驶员手机号
          driver: driver ? `${driver.split("=")[1]}-${driver.split("=")[2]}` : "",
          // 出发时间
          stime: it.stime,
          // 结束时间
          etime: it.etime,
          // 行程详情
          routeDetail: it.routeDetail.replace(/@/g, '<br />'),
          // 客户备注
          cusNote: it.cusNote,
          // 驾驶员备注
          driverNote: it.driverNote,
          // 业务员备注
          serviceNote: it.serviceNote,
          // 用车单位：用户名=姓名=手机号
          companyName: `${it.carOrderBase.customId.baseUserId.uname}=${it.carOrderBase.customId.baseUserId.realName}=${it.carOrderBase.customId.baseUserId.phone}`,
          // 联系人：用户名=姓名=手机号
          dutyBaseUser: `${it.carOrderBase.dutyBaseUser.uname}=${it.carOrderBase.dutyBaseUser.realName}=${it.carOrderBase.dutyBaseUser.phone}`,
          // 业务员：：用户名=姓名=手机号
          serviceManName: it.carOrderBase.serviceMan,
          // 订单价格（单车运价*所需车辆数）
          price: it.price,
          // 其他费用
          otherPrice: it.otherPrice,
          // 已收金额
          alGathPrice: it.alPayPrice,
          // 旅网金额
          travelPrepayPrice: it.travelPrepayPrice == 0 ? "" : it.travelPrepayPrice,
          // 自网金额
          selfPrepayPrice: it.selfPrepayPrice == 0 ? "" : it.selfPrepayPrice,
          // 外调状态
          isExternalName: it.useSelf == 1 ? '否' : '是',
          //是否滴滴打车订单设置 
          isUseDidi: it.isUseDidi,
          // 行程联系人
          routeLink: it.carOrderBase.routeLink,
          // 业务类型
          serviceType: serviceType ? serviceType.label : "",
          // 添加时间
          addTime: it.carOrderBase.addTime,
          // 指定用车
          regularCar: it.carOrderBase.regularCar,
          // 行程地点信息
          dayMps: it.dayMps,
          // 合并-取消标记
          mergeMark: it.mergeMark,
          // 代收二维码地址
          helpGathUrl: it.helpGathUrl,
          // 代收金额
          helpGathPrice: it.helpGathPrice,
          // 异常报备
          accidentRecord: it.disCarId ? it.disCarId.accidentRecord : "",
        };
        resList.push(obj);
      });

      // 赋值-当前页总价
      that.tj.pageTotalPrice = pageTotalPrice;
      console.log('resList', resList);
      return resList;
    },
    /**
     * 获取-订单分页列表
     */
    getDgList() {
      let that = this, U = that.U, ps = U.scopy(that.dg.ps);

      // 参数处理
      if (ps.setime && ps.setime.length == 2) {
        ps.startTime = ps.setime[0];
        ps.endTime = ps.setime[1];
      } else {
        ps.startTime = "";
        ps.endTime = "";
      }
      delete ps.setime;

      // 处理订单状态
      ps.orderStatus = ps.orderStatus.join(',');
      if (ps.orderNum) ps.orderNum = U.trim(ps.orderNum);

      orderService.getDisorderPageList(ps).then((res) => {
        if (!res || res.code != 1) {
          U.qerror("数据请求失败");
        } else {
          let list = res.data;
          // 保存-列表数据对象名称
          list.forEach((it) => { it.dgName = that.dg.dgName; });

          // 保存-原数据列表，方便查询（放这里需要保存dgName参数）
          that.resDgList = list;

          that.dg.list = that.filterDgList(list);
          that.dg.total = res.count;


          // 统计数据
          let tj = res.statics;
          that.tj = {
            // 车辆总数
            carCount: tj.carCount,
            // 订单总价
            totalPrice: tj.totalPrice,
            // 未派车
            noCar: tj.noCar,
            // 未定价
            noPrice: tj.noPrice,
            // 未通知
            jlNotConfirm: tj.jlNotConfirm,
            // 已通知
            driverNotConfirm: tj.driverNotConfirm,
            // 已确认
            driverConfirm: tj.driverConfirm,
            // 运行中
            travel: tj.travel,
            // 已完团
            complete: tj.complete,
          };
        }
      });
    },
    headerStyle({ row, column, rowIndex, columnIndex }) {
      // if (column.label == '车型') {
      //   return { 'border': '2px solid red', 'border-bottom': 'none' };
      // }
    },

    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (column.label == '车型' && row.regularCar == 1) {
        return { 'border': '2px solid red' };
      } else if (column.label == '订单状态' && row.isUseDidi == 1) {
        return { 'border': '2px solid red' };
      }


    },
    /** 设置行背景颜色 */
    rowStyle({ row, rowIndex }) {
      let status = row.status.val;
      // let regularCar = row.regularCar
      // if (regularCar == 1) {
      //   console.log(row)
      // }

      
      if (status == 'NOT_DIS_CAR') {
        // 未派车=行背景为：白色 黑字
        return { 'background': '#ffffff', 'color': '#000000', 'font-weight': '600' };
      } else if (status == 'JL_NOT_CONFIRM') {
        // 未通知（已预派）=行背景：粉红 黑字 
        return { 'background': '#FBAEAA', 'color': '#000000', 'font-weight': '600' };
      } else if (status == 'DRIVER_NOT_CONFIRM') {
        // 师傅未确认(即已通知)=行背景为：蓝色
        return { 'background': '#a9befd', 'color': '#fff', 'font-weight': '600' };
      } else if (status == 'DRIVER_CONFIRMED') {
        // 师傅已确认=行背景为：深绿色 白字
        return { 'background': '#045155', 'color': '#fff', 'font-weight': '600' };
      } else if (status == 'AL_TRAVEL') {
        // 已出行（即运行中）=行背景为：绿色
        return { 'background': '#a1d28a', 'color': '#fff', 'font-weight': '600' };
      } else if (status == 'COMPLETED') {
        // 已完团=行背景为：粉红
        return { 'background': '#ffbebe', 'color': '#fff', 'font-weight': '600' };
      } else if (status == 'START_TAKE_CUS') {
        // 已完团=行背景为：橙色
        return { 'background': '#FDCAA9', 'color': '#fff', 'font-weight': '600' };
      }

      // 任何状态下，只要价格为0，即为：未定价
      if (row.price == 0) {
        // 没有价格=行背景为：红色
        return { 'background': '#f00', 'color': '#fff', 'font-weight': '600' };
      }

      return {};
    },
    // 派车-弹框
    disCarMd(e) {
      // 派车类型（disType）：0-线上派车/线下派车；1-线上派车；2-线下派车；
      let that = this, U = that.U, md = that.md.disCar, rows = that.getSeledRows(), disType = 0;;

      if (!e.state) {// 关闭弹框
        md.state = e.state;
      } else {// 打开弹框
        if (rows.length > 1) {
          // 选择了多个子订单，必须是在同一主订单下，且只能线下派单
          let sons = [], fg = true, oldRow = null, isDiff = -1;
          for (let i = 0; i < rows.length; i++) {
            let row = rows[i], num = row.index + 1;

            // 保存订单
            sons.push(row);

            if (!oldRow) oldRow = row;

            if (row.isMain) {
              fg = U.qerrorFalse(`编号 ${num} 订单是主订单：主订单不能派车`);
              break;
            } else if (row.plateNum) {
              fg = U.qerrorFalse(`编号 ${num} 订单已派车`);
              break;
            } else if (oldRow.mainOrderNum != row.mainOrderNum) {
              fg = U.qerrorFalse(`编号 ${num} 订单的主订单与其他订单的主订单不一样`);
              break;
            } else if (oldRow.routeDetail != row.routeDetail || oldRow.seats != row.seats) {
              // 行程不一样
              isDiff = num;
            }
          }
          if (!fg) return;

          if (isDiff > 0) {// 行程存在不一样，需要提示用户将会进入线下派车
            U.qconfim(`编号 ${isDiff} 订单的行程与其他订单的行程不一样，点击确定<span class="c-red">进入线下派车</span>？`).then(r => {
              if (r) {
                md.orders = sons;
                // 多条订单时：存在不同行程订单则只能线下派车
                md.disType = 2;
                md.state = e.state;
              }
            });
          } else {// 行程一样，直接进入线上派车
            md.orders = sons;
            // 多条订单时：存在不同行程订单则只能线上派车；
            md.disType = 1;
            md.state = e.state;
          }
        } else {// 选择了单条子订单，可以线上/线下派单
          md.orders = [e.obj];
          md.disType = disType;
          md.state = e.state;
        }
      }

      // if (e.state) {
      //   // 打开弹框
      //   if (rows.length == 0) {
      //     U.qerror("请至少选择一条数据");
      //   } else {
      //     if(rows.length > 1){
      //         // 选择了多个子订单，必须是在同一主订单下，且只能线下派单
      //         let sons = [], mon = null, fg = true;
      //         for(let i = 0; i < rows.length; i++){
      //             let row = rows[i];

      //             // 保存订单
      //             sons.push(row);

      //             if(!mon) mon = row.mainOrderNum;

      //             if(row.plateNum){
      //               fg = U.qerrorFalse(`选中的第${i + 1}条订单已派车，不能再次派车！`);
      //               break;
      //             }else if(mon != row.mainOrderNum){
      //               fg = U.qerrorFalse(`选择的订单中存在于不同主订单`);
      //               break;
      //             }
      //         }
      //         if(!fg) return;

      //         md.orders = sons;

      //         md.state = e.state;
      //     }else{// 选择了单条子订单，可以线上/线下派单
      //       let orderNums = [], preOrder = null, fg = true;
      //       for (let i = 0; i < rows.length; i++) {
      //         let o = rows[i];
      //         if (o.plateNum) {
      //           fg = U.qerrorFalse(`选中的第${i + 1}条订单已派车，不能再次派车！`);
      //           break;
      //         } else if (preOrder && preOrder.seats != o.seats) {
      //           fg = U.qerrorFalse(`选中的订单座位数不一样，请重新选择！`);
      //           break;
      //         } else if (preOrder && preOrder.routeDetail != o.routeDetail) {
      //           fg = U.qerrorFalse(`选中的订单行程详情不一样，请重新选择！`);
      //           break;
      //         } else {
      //           orderNums.push(o.orderNum);

      //           preOrder = o;
      //         }
      //       }

      //       if (fg) {
      //         // 派单订单编号
      //         md.sendOrderNum = orderNums.join(",");
      //         // 派单所需座位数
      //         md.needSeats = preOrder.needSeats;

      //         // 线下派单-数据
      //         md.orders = [preOrder];

      //         md.state = e.state;
      //       }
      //     }
      //   }
      // }
    },
    /**
     * 获取-单位所有业务员
     */
    getCompanyAllSalesman() {
      const that = this;
      let ps = { staffState: "NORMAL,TRY", deptName: '业务部' };
      cusService.getCompanyAllSalesman(ps).then((res) => {
        that.serviceManList = res.data;
      });
    },
    // /**
    //  * 获取-单位所有客户
    //  * @param cusType 查询类型 合作车队/公司/PARTUNIT
    //  */
    // cusUnameList(cusType) {
    //   const that = this;

    //   if (!cusType) cusType = "";

    //   commService.getCompanyCusList({ cusType: cusType }).then((res) => {
    //     that.clientList = res.data;
    //   });
    // },
    /**
     * 选择客户-获取联系人
     */
    selectCus(uname) {
      const that = this;

      that.dg.ps.dutyMan = "";
      orderService.geDutysByCuList({ cusUname: uname }).then((res) => {
        that.dutyManList = res.data;
      });
    },

    /**
     * 获取-供车方单位列表
     */
    getSuppCarComList() {
      const that = this;

      commService.getCompanyCusList({ cusType: "CARTEAM" }).then((res) => {
        that.suppCarComList = res.data;
      });
    },
    /**
     * 选择供车方单位-获取供车方负责人
     */
    selectSuppCarCom(obj) {
      const that = this;

      let arr = obj.dutyService ? obj.dutyService.split('-') : [];
      that.suppCarDutyManList = arr.length > 0 ? [{ uname: arr[0], realName: arr[1], phone: arr[2] }] : [];
      that.dg.ps.suppMan = that.suppCarDutyManList.length > 0 ? that.suppCarDutyManList[0].uname : '';
    },
    // /**
    //  * 选择供车方单位-获取供车方负责人
    //  */
    // selectSuppCarCom(uname) {
    //   const that = this;

    //   that.dg.ps.suppMan = "";
    //   orderService.geDutysByCuList({ cusUname: uname }).then((res) => {
    //     that.suppCarDutyManList = res.data;
    //   });
    // },
    // /**
    //  * 打开添加弹框
    //  */
    // addOrderMdState(e) {
    //   this.md.addOrder.state = e;
    // },
    /**
     * 将列表行主订单数据处理成表单数据
     * @param mo 列表行数据主订单对象
     * @returns 处理后的主订单表单数据对象
     */
    getFmMainOrder(mo) {
      const that = this;

      /** 获取当前主订单下所有天数行程数据--begin */
      let dayMps = [];
      mo.carOrders.forEach((it) => {
        it.dayMps.forEach((it2) => {
          let is = dayMps.find(
            (t) => `${it2.stime}=${it2.etime}` == `${t.stime}=${t.etime}`
          );
          if (!is) dayMps.push(it2);
        });
      });
      /** 获取当前主订单下所有天数行程数据--end */

      /** 选择的主订单的第一条子订单 */
      let o = mo.carOrders[0];

      // 处理添加订单所需要的数据
      let co = {};

      // 订单编号
      co.orderNum = o.orderNum;
      // 是否是主订单
      co.isMain = 1;
      // 团号
      co.groupNum = o.carOrderBase.routeName;
      // 操作员-用户名
      co.operator = o.carOrderBase.dutyBaseUser.uname;
      // 用车客户-用户名
      co.useCarUname = o.carOrderBase.customId.baseUserId.uname;
      // 联系人
      co.routeLink = {
        // 姓名
        name: o.carOrderBase.routeLink.split("-")[0],
        // 手机号
        phone: o.carOrderBase.routeLink.split("-")[1],
      };
      // 业务员
      co.serviceMan = {
        // 用户名
        uname: o.carOrderBase.serviceMan.split("-")[0],
        // 姓名
        name: o.carOrderBase.serviceMan.split("-")[1],
        // 手机号
        phone: o.carOrderBase.serviceMan.split("-")[2],
      };
      // 行程简称（取第一天行程的行程简称）
      co.routeShort = o.routeSimpleName;

      // 天数行程数组
      let dayRoutes = [];
      dayMps.forEach((it, i) => {
        let dr = {};

        // 编号
        dr.no = i + "";
        // 出发日期 2021-01-01
        dr.goDate = it.stime.split(" ")[0];
        // 开始时间 10:30
        dr.stime = it.stime.substr(11, 5);
        // 结束时间 20:00
        dr.etime = it.etime.substr(11, 5);
        // 出发地点
        dr.spoint = {
          // 区域
          area: `${it.spoint.city}-${it.spoint.county}`,
          // 地址详情 成都市 武侯区 天府广场
          address: it.spoint.address,
          // 地址简称 天府广场
          name: it.spoint.address.split(" ")[1],
          // 地点坐标 140.xxxxxx,30.xxxxxx
          lnglat: it.spoint.lngLat,
          // 是否是站点 true-是 false-不是
          isSta: it.spoint.isSta == 1 ? true : false,
        };
        // 上午地点数组
        let amPoints = [];
        if (it.morningPoint.length > 0) {
          it.morningPoint.forEach((amit) => {
            amPoints.push({
              id: amit.id + "",
              // 区域
              area: `${amit.city}-${amit.county}`,
              // 地址详情 成都市 武侯区 天府广场
              address: amit.address,
              // 地址简称 天府广场
              name: amit.address.split(" ")[1],
              // 地点坐标 140.xxxxxx,30.xxxxxx
              lnglat: amit.lngLat,
              // 是否是站点 true-是 false-不是
              isSta: amit.isSta == 1 ? true : false,
            });
          });
        }
        dr.amPoints = amPoints;
        // 午餐地点
        dr.lunchPoint = !it.lunchPoint
          ? null
          : {
            // 区域
            area: `${it.lunchPoint.city}-${it.lunchPoint.county}`,
            // 地址详情 成都市 武侯区 天府广场
            address: it.lunchPoint.address,
            // 地址简称 天府广场
            name: it.lunchPoint.address.split(" ")[1],
            // 地点坐标 140.xxxxxx,30.xxxxxx
            lnglat: it.lunchPoint.lngLat,
            // 是否是站点 true-是 false-不是
            isSta: it.lunchPoint.isSta == 1 ? true : false,
          };
        // 下午地点数组
        let pmPoints = [];
        if (it.afternoonPoint.length > 0) {
          it.afternoonPoint.forEach((pmit) => {
            pmPoints.push({
              id: pmit.id + "",
              // 区域
              area: `${pmit.city}-${pmit.county}`,
              // 地址详情 成都市 武侯区 天府广场
              address: pmit.address,
              // 地址简称 天府广场
              name: pmit.address.split(" ")[1],
              // 地点坐标 140.xxxxxx,30.xxxxxx
              lnglat: pmit.lngLat,
              // 是否是站点 true-是 false-不是
              isSta: pmit.isSta == 1 ? true : false,
            });
          });
        }
        dr.pmPoints = pmPoints;
        // 晚餐地点
        dr.dinnerPoint = !it.dinnerPoint
          ? null
          : {
            // 区域
            area: `${it.dinnerPoint.city}-${it.dinnerPoint.county}`,
            // 地址详情 成都市 武侯区 天府广场
            address: it.dinnerPoint.address,
            // 地址简称 天府广场
            name: it.dinnerPoint.address.split(" ")[1],
            // 地点坐标 140.xxxxxx,30.xxxxxx
            lnglat: it.dinnerPoint.lngLat,
            // 是否是站点 true-是 false-不是
            isSta: it.dinnerPoint.isSta == 1 ? true : false,
          };
        // 结束地点
        dr.epoint = {
          // 区域
          area: `${it.epoint.city}-${it.epoint.county}`,
          // 地址详情 成都市 武侯区 天府广场
          address: it.epoint.address,
          // 地址简称 天府广场
          name: it.epoint.address.split(" ")[1],
          // 地点坐标 140.xxxxxx,30.xxxxxx
          lnglat: it.epoint.lngLat,
          // 是否是站点 true-是 false-不是
          isSta: it.epoint.isSta == 1 ? true : false,
        };
        // 可换车
        // dr.changeCar = {
        //     // 状态 0-否；1-是；
        //     check: (dayMps.length > 1 && o.routeSimpleName) ? 1 : 0,
        //     // 运价设置
        //     transportPrice: o.price,
        //     // 师傅现收
        //     remindRouteCash: o.remDriverCharge,
        //     // 其他设置
        //     otherFees: o.otherPrice,
        //     // 途径高速
        //     wayHighSpeed: o.highSpeed,
        //     // 行程简称
        //     routeShort: o.routeSimpleName
        // };
        dr.changeCar = {
          // 状态 0-否；1-是；
          check: 0,
          // 运价设置
          transportPrice: "",
          // 师傅现收
          remindRouteCash: "",
          // 其他设置
          otherFees: "",
          // 途径高速
          wayHighSpeed: "",
          // 行程简称
          routeShort: "",
        };
        // 临空时间数组
        let emptyTimes = [];
        // 找到指定行程id对应的临空时间对象
        let fts = o.freeTimes.filter((ftit) => ftit.dayRouteId == it.id);
        if (fts.length > 0) {
          fts.forEach((ftit, index) => {
            emptyTimes.push({
              no: index + "",
              stime: ftit.freeStime.substr(11, 5),
              etime: ftit.freeEtime.substr(11, 5),
              // 停靠地点
              stopPoint: {
                id: index + 1 + "",
                // 区域
                area: `${ftit.stayPoint.city}-${ftit.stayPoint.county}`,
                // 地址详情 成都市 武侯区 天府广场
                address: ftit.stayPoint.address,
                // 地址简称 天府广场
                name: ftit.stayPoint.address.split(" ")[1],
                // 地点坐标 140.xxxxxx,30.xxxxxx
                lnglat: ftit.stayPoint.lngLat,
                // 是否是站点 true-是 false-不是
                isSta: ftit.stayPoint.isSta == 1 ? true : false,
              },
              // 返回地点
              backPoint: {
                id: index + 2 + "",
                // 区域
                area: `${ftit.returnPoint.city}-${ftit.returnPoint.county}`,
                // 地址详情 成都市 武侯区 天府广场
                address: ftit.returnPoint.address,
                // 地址简称 天府广场
                name: ftit.returnPoint.address.split(" ")[1],
                // 地点坐标 140.xxxxxx,30.xxxxxx
                lnglat: ftit.returnPoint.lngLat,
                // 是否是站点 true-是 false-不是
                isSta: ftit.returnPoint.isSta == 1 ? true : false,
              },
            });
          });
        }
        dr.emptyTimes = emptyTimes;
        // 开始/结束地点的航班/车次查询信息
        let seStaInfo = null;
        if (it.routeStationInfo) {
          let infoText = "",
            type = it.routeStationInfo.type,
            jsType = it.routeStationInfo.isShuttle,
            num = it.routeStationInfo.num,
            time = it.routeStationInfo.seltime?.substr(11, 5);

          if (time && num) {
            if (type == 1) {
              // 飞机
              if (jsType == 1) {
                // 接
                infoText = `${num}降落${time}`;
              } else {
                // 送
                infoText = `${num}起飞${time}`;
              }
            } else if (type == 2) {
              // 火车
              if (jsType == 1) {
                // 接
                infoText = `${num}到达${time}`;
              } else {
                // 送
                infoText = `${num}出发${time}`;
              }
            }
          }

          seStaInfo = {
            // 航班/车次号
            flightTrainNo: num,
            // 降落/起飞/进站/出站时间
            downUpTime: it.routeStationInfo.seltime,
            // 查询信息
            infoText: infoText,
            // 站点名称
            selStaName: it.routeStationInfo.stationName,
            // 交通类型
            type: type,
            // 接送类型
            jsType: jsType,
          };
        }
        dr.seStaInfo = seStaInfo;
        // 其他地点航班/车次信息数组 D638=2021-04-21 07:10=2=2=火车东站/@G3286=2021-04-21 07:23=2=2=火车东站
        let wpStaInfos = [];
        if (it.otherStationInfo) {
          let oss = it.otherStationInfo.split("/@");
          oss.forEach((osit) => {
            let os = osit.split("=");
            let infoText = "",
              num = os[0],
              time = os[1].substr(11, 5),
              type = os[2],
              jsType = os[3];
            if (type == 1) {
              // 飞机
              if (jsType == 1) {
                // 接
                infoText = `${num}降落${time}`;
              } else {
                // 送
                infoText = `${num}起飞${time}`;
              }
            } else if (type == 2) {
              // 火车
              if (jsType == 1) {
                // 接
                infoText = `${num}到达${time}`;
              } else {
                // 送
                infoText = `${num}出发${time}`;
              }
            }

            wpStaInfos.push({
              // 航班/车次号
              flightTrainNo: num,
              // 降落/起飞/进站/出站时间
              downUpTime: os[1],
              // 查询信息
              infoText: infoText,
              // 站点名称
              selStaName: os[4],
              // 交通类型
              type: type,
              // 接送类型
              jsType: jsType,
            });
          });
        }
        dr.wpStaInfos = wpStaInfos;

        dayRoutes.push(dr);
      });
      co.dayRoutes = dayRoutes;
      // 座位数
      co.seats = o.needSeats;
      // 人数
      co.customers = o.customers;
      // 车辆数
      co.cars = mo.needCars;
      // 运价
      co.transportPrice = mo.price;
      // 其他费用
      co.otherFees = mo.otherPrice;
      // 订单总价
      let totalPrice = 0;
      if (that.FV.isNumber(co.transportPrice) && co.transportPrice) {
        totalPrice += parseFloat(co.transportPrice);
      }
      if (that.FV.isNumber(co.otherFees) && co.otherFees) {
        totalPrice += parseFloat(co.otherFees);
      }
      co.orderTotalPrice = totalPrice;
      // 定金
      co.deposit = mo.handSelPrice;
      // 师傅现收
      co.remindRouteCash = mo.remDriverCharge;
      // 途径高速
      co.wayHighSpeed = o.highSpeed;
      // 订单业务类型
      co.orderServiceType = mo.serviceType;
      // 行程详情
      let routeDetail = [];
      mo.carOrders.forEach((it) => {
        routeDetail.push(it.routeDetail);
      });
      co.routeDetail = routeDetail.join("\n");
      // 客户备注
      co.cusNote = o.cusNote;
      // 驾驶员备注
      co.driverNote = o.driverNote;
      // 业务员备注
      co.salesmanNote = o.serviceNote;
      // 是否用自己的车 0-不用；1-用；
      co.useSelfCar = o.useSelf;

      return co;
    },
    /**
     * 将列表行子订单数据处理成表单数据
     * @param o 列表行数据子订单对象
     * @returns 处理后的子订单表单数据对象
     */
    getFmChildOrder(o) {
      const that = this;
      // console.log('修改订单', o);

      // 处理添加订单所需要的数据
      let co = {};
      // 订单编号
      co.orderNum = o.orderNum;
      // 主订单编号
      co.mainOrderNum = o.mainOrderNum;
      // 派车车辆
      co.plateNum = o.disCarId ? o.disCarId.plateNum : '';
      // 团号
      co.groupNum = o.carOrderBase.routeName;
      // 操作员-用户名
      co.operator = o.carOrderBase.dutyBaseUser.uname;
      // 用车客户-用户名
      co.useCarUname = o.carOrderBase.customId.baseUserId.uname;
      // 联系人
      co.routeLink = {
        // 姓名
        name: o.carOrderBase.routeLink.split("-")[0],
        // 手机号
        phone: o.carOrderBase.routeLink.split("-")[1],
      };
      // 业务员
      co.serviceMan = {
        // 用户名
        uname: o.carOrderBase.serviceMan.split("-")[0],
        // 姓名
        name: o.carOrderBase.serviceMan.split("-")[1],
        // 手机号
        phone: o.carOrderBase.serviceMan.split("-")[2],
      };
      // 行程简称（取第一天行程的行程简称）
      co.routeShort = o.routeSimpleName;

      // 天数行程数组
      let dayRoutes = [];
      o.dayMps.forEach((it, i) => {
        let dr = {};
        // id
        dr.id = it.id;
        // 编号
        dr.no = i + "";
        // 出发日期 2021-01-01
        dr.goDate = it.stime.split(" ")[0];
        // 开始时间 10:30
        dr.stime = it.stime.substr(11, 5);
        // 结束时间 20:00
        dr.etime = it.etime.substr(11, 5);
        // 出发地点
        let spointArr = it.spoint.address.split(' ');
        dr.spoint = {
          // 区域
          area: `${it.spoint.city}-${it.spoint.county}`,
          // 地址详情 成都市 武侯区 天府广场
          address: it.spoint.address,
          // 地址简称 天府广场
          name: spointArr.length > 1 ? spointArr[1] : spointArr[0],
          // 地点坐标 140.xxxxxx,30.xxxxxx
          lnglat: it.spoint.lngLat,
          // 是否是站点 true-是 false-不是
          isSta: it.spoint.isSta == 1 ? true : false,
        };
        // 上午地点数组
        let amPoints = [];
        if (it.morningPoint.length > 0) {
          it.morningPoint.forEach((amit) => {
            amPoints.push({
              id: amit.id + "",
              // 区域
              area: `${amit.city}-${amit.county}`,
              // 地址详情 成都市 武侯区 天府广场
              address: amit.address,
              // 地址简称 天府广场
              name: amit.address.split(" ")[1],
              // 地点坐标 140.xxxxxx,30.xxxxxx
              lnglat: amit.lngLat,
              // 是否是站点 true-是 false-不是
              isSta: amit.isSta == 1 ? true : false,
            });
          });
        }
        dr.amPoints = amPoints;
        // 午餐地点
        dr.lunchPoint = !it.lunchPoint
          ? null
          : {
            // 区域
            area: `${it.lunchPoint.city}-${it.lunchPoint.county}`,
            // 地址详情 成都市 武侯区 天府广场
            address: it.lunchPoint.address,
            // 地址简称 天府广场
            name: it.lunchPoint.address.split(" ")[1],
            // 地点坐标 140.xxxxxx,30.xxxxxx
            lnglat: it.lunchPoint.lngLat,
            // 是否是站点 true-是 false-不是
            isSta: it.lunchPoint.isSta == 1 ? true : false,
          };
        // 下午地点数组
        let pmPoints = [];
        if (it.afternoonPoint.length > 0) {
          it.afternoonPoint.forEach((pmit) => {
            pmPoints.push({
              id: pmit.id + "",
              // 区域
              area: `${pmit.city}-${pmit.county}`,
              // 地址详情 成都市 武侯区 天府广场
              address: pmit.address,
              // 地址简称 天府广场
              name: pmit.address.split(" ")[1],
              // 地点坐标 140.xxxxxx,30.xxxxxx
              lnglat: pmit.lngLat,
              // 是否是站点 true-是 false-不是
              isSta: pmit.isSta == 1 ? true : false,
            });
          });
        }
        dr.pmPoints = pmPoints;
        // 晚餐地点
        dr.dinnerPoint = !it.dinnerPoint
          ? null
          : {
            // 区域
            area: `${it.dinnerPoint.city}-${it.dinnerPoint.county}`,
            // 地址详情 成都市 武侯区 天府广场
            address: it.dinnerPoint.address,
            // 地址简称 天府广场
            name: it.dinnerPoint.address.split(" ")[1],
            // 地点坐标 140.xxxxxx,30.xxxxxx
            lnglat: it.dinnerPoint.lngLat,
            // 是否是站点 true-是 false-不是
            isSta: it.dinnerPoint.isSta == 1 ? true : false,
          };
        // 结束地点
        let epointArr = it.epoint.address.split(' ');
        dr.epoint = {
          // 区域
          area: `${it.epoint.city}-${it.epoint.county}`,
          // 地址详情 成都市 武侯区 天府广场
          address: it.epoint.address,
          // 地址简称 天府广场
          name: epointArr.length > 1 ? epointArr[1] : epointArr[0],
          // 地点坐标 140.xxxxxx,30.xxxxxx
          lnglat: it.epoint.lngLat,
          // 是否是站点 true-是 false-不是
          isSta: it.epoint.isSta == 1 ? true : false,
        };
        // 可换车（已取消）
        dr.changeCar = {
          // 状态 0-否；1-是；
          check: 0,
          // 运价设置
          transportPrice: "",
          // 师傅现收
          remindRouteCash: "",
          // 其他设置
          otherFees: "",
          // 途径高速
          wayHighSpeed: "",
          // 行程简称
          routeShort: "",
        };
        // 临空时间数组
        let emptyTimes = [];
        // 找到指定行程id对应的临空时间对象
        let fts = o.freeTimes.filter((ftit) => ftit.dayRouteId == it.id);
        if (fts.length > 0) {
          fts.forEach((ftit, index) => {
            emptyTimes.push({
              dayId: ftit.dayRouteId + "",
              freeId: ftit.id + "",
              no: index + "",
              stime: ftit.freeStime.substr(11, 5),
              etime: ftit.freeEtime.substr(11, 5),
              // 停靠地点
              stopPoint: {
                id: index + 1 + "",
                // 区域
                area: `${ftit.stayPoint.city}-${ftit.stayPoint.county}`,
                // 地址详情 成都市 武侯区 天府广场
                address: ftit.stayPoint.address,
                // 地址简称 天府广场
                name: ftit.stayPoint.address.split(" ")[1],
                // 地点坐标 140.xxxxxx,30.xxxxxx
                lnglat: ftit.stayPoint.lngLat,
                // 是否是站点 true-是 false-不是
                isSta: ftit.stayPoint.isSta == 1 ? true : false,
              },
              // 返回地点
              backPoint: {
                id: index + 2 + "",
                // 区域
                area: `${ftit.returnPoint.city}-${ftit.returnPoint.county}`,
                // 地址详情 成都市 武侯区 天府广场
                address: ftit.returnPoint.address,
                // 地址简称 天府广场
                name: ftit.returnPoint.address.split(" ")[1],
                // 地点坐标 140.xxxxxx,30.xxxxxx
                lnglat: ftit.returnPoint.lngLat,
                // 是否是站点 true-是 false-不是
                isSta: ftit.returnPoint.isSta == 1 ? true : false,
              },
            });
          });
        }
        dr.emptyTimes = emptyTimes;

        // 开始/结束地点的航班/车次查询信息
        let seStaInfo = null;
        if (it.routeStationInfo) {
          let infoText = "",
            type = it.routeStationInfo.type,
            jsType = it.routeStationInfo.isShuttle,
            num = it.routeStationInfo.num,
            time = it.routeStationInfo.seltime?.substr(11, 5);

          if (time && num) {
            if (type == 1) {
              // 飞机
              if (jsType == 1) {
                // 接
                infoText = `${num}降落${time}`;
              } else {
                // 送
                infoText = `${num}起飞${time}`;
              }
            } else if (type == 2) {
              // 火车
              if (jsType == 1) {
                // 接
                infoText = `${num}到达${time}`;
              } else {
                // 送
                infoText = `${num}出发${time}`;
              }
            }
          }

          seStaInfo = {
            // 航班/车次号
            flightTrainNo: num,
            // 降落/起飞/进站/出站时间
            downUpTime: it.routeStationInfo.seltime,
            // 查询信息
            infoText: infoText,
            // 站点名称
            selStaName: it.routeStationInfo.stationName,
            // 交通类型
            type: type,
            // 接送类型
            jsType: jsType,
          };
        }
        dr.seStaInfo = seStaInfo;

        // 其他地点航班/车次信息数组 D638=2021-04-21 07:10=2=2=火车东站/@G3286=2021-04-21 07:23=2=2=火车东站
        let wpStaInfos = [];
        if (it.otherStationInfo) {
          let oss = it.otherStationInfo.split("/@");
          oss.forEach((osit) => {
            let os = osit.split("=");
            let infoText = "",
              num = os[0],
              time = os[1].substr(11, 5),
              type = os[2],
              jsType = os[3];
            if (type == 1) {
              // 飞机
              if (jsType == 1) {
                // 接
                infoText = `${num}降落${time}`;
              } else {
                // 送
                infoText = `${num}起飞${time}`;
              }
            } else if (type == 2) {
              // 火车
              if (jsType == 1) {
                // 接
                infoText = `${num}到达${time}`;
              } else {
                // 送
                infoText = `${num}出发${time}`;
              }
            }

            wpStaInfos.push({
              // 航班/车次号
              flightTrainNo: num,
              // 降落/起飞/进站/出站时间
              downUpTime: os[1],
              // 查询信息
              infoText: infoText,
              // 站点名称
              selStaName: os[4],
              // 交通类型
              type: type,
              // 接送类型
              jsType: jsType,
            });
          });
        }
        dr.wpStaInfos = wpStaInfos;
        // 途径高速
        dr.wayHighSpeed = it.highSpeed;

        dayRoutes.push(dr);
      });
      co.dayRoutes = dayRoutes;
      // 座位数
      co.seats = o.needSeats;
      // 人数
      co.customers = o.customers;
      // 车辆数
      co.cars = 1;
      // 天数
      co.transportPrice = o.price;
      // 运价
      co.useCarDays = o.useCarDays;
      // 其他费用
      co.otherFees = o.otherPrice;
      // 订单总价
      co.orderTotalPrice = parseFloat(co.transportPrice) + parseFloat(co.otherFees);
      // 定金（子订单没有定金）
      co.deposit = 0;
      // 师傅现收
      co.remindRouteCash = o.remDriverCharge;
      // 途径高速（已移至每日行程中）
      // co.wayHighSpeed = o.highSpeed;
      // 订单业务类型
      co.orderServiceType = o.serviceType;
      // 行程详情
      co.routeDetail = o.routeDetail;
      // 客户备注
      co.cusNote = o.cusNote;
      // 驾驶员备注
      co.driverNote = o.driverNote;
      // 业务员备注
      co.salesmanNote = o.serviceNote;
      // 是否用自己的车 0-不用；1-用；
      co.useSelfCar = o.useSelf;
      // 是否交通车 0-否 1-是
      co.isTrans = o.isTrans;
      // 固定车
      co.fixedCar = o.fixedCar;
      // 固定人
      co.fixedDriver = o.fixedDriver;

      return co;
    },
    /**
     * 打开修改弹框
     */
    updOrderMdState(e) {
      const that = this;
      this.md.updOrder.state = e;
    },
    // 修改子订单
    editChildOrder() {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length != 1) {
        U.qerror(`您选择了${rows.length}条数据，请选择一条数据`);
      } else {
        let row = rows[0];
        if (row.isSplit == 1) {
          U.qerror(`选中的子订单已拆分，不能修改！`);
        } else {
          let co = that.resDgList.find((o) => row.id == o.id);
          if (!co) {
            U.qerror(`选中的订单已不存在，请重新选择！`);
          } else if (co.isSplit == 1) {
            U.qerror(`选中的订单已拆分，不能修改！`);
          } else {
            that.md.updOrder.order = that.getFmChildOrder(co);

            // 通过请求，获取同级订单
            let loading = U.qloading("请稍后...");
            let ps = { mainOrderNum: co.mainOrderNum, orderNum: co.orderNum };
            orderService.getAllOrderByMainOrderNum(ps).then(res => {
              U.qclose(loading);

              if (res.code == 1) {
                let list = [];
                res.data.forEach(it => {
                  if (it.isTrans == 1) {
                    // 交通车，不保存已派车的订单
                    if (!it.disCarId || !it.disCarId.plateNum) list.push(that.getFmChildOrder(it));
                  } else {
                    // 保存同级子订单至数组中
                    list.push(that.getFmChildOrder(it));
                  }
                });
                // 除当前选中的子订单之外的兄弟订单数组
                that.md.updOrder.order.otherOrders = list || [];

                // 打开修改订单弹框
                that.updOrderMdState({ state: true });
              }
            }).catch((err) => { U.qclose(loading); });
          }
        }
      }
    },
    // 复制子订单（在所选订单所属主订单下面新增一个订单）
    copyChildOrder() {
      const that = this, rows = that.getSeledRows();

      if (rows.length != 1) {
        that.U.qerror(`您选择了${rows.length}条数据，请选择一条数据`);
      } else {
        let row = rows[0];
        if (row.isSplit == 1) {
          that.U.qerror(`选中的订单已被拆分，不能复制！`);
        } else {
          // 找到当前选择数据的原数据订单对象
          let co = that.resDgList.find((o) => {
            return o.id == row.id;
          });
          if (!co) {
            that.U.qerror(`选中的订单已不存在，请重新选择！`);
          } else {
            that.md.updOrder.order = that.getFmChildOrder(co);
            // 设置一个标志参数，方便修改页面判断已便调用复制子订单接口
            that.md.updOrder.order.isCopy = 1;
            // 打开修改订单弹框
            that.updOrderMdState({ state: true });
          }
        }
      }
    },
    /**
     * 通知驾驶员
     * @param row 通知的行
     */
    noticeDriver(row) {
      let that = this, U = that.U, rows = that.getSeledRows(), resRows = [];

      if (rows.length == 0) {
        // 如果未选择数据，则点击‘任意’按钮，则只对按钮对应行数据进行通知
        resRows = [row];
      } else {
        // 如果选择了数据，则点击任意‘通知’按钮，都可以进行通知（如果点击按钮行未选中，则不会通知该行）
        resRows = rows;
      }

      let ids = [], fg = true;
      for (let i = 0; i < resRows.length; i++) {
        let it = resRows[i];
        if (it.status.val != "JL_NOT_CONFIRM") {
          U.qerror(`选中的第${i + 1}条订单：只有“已预派”的订单才能通知`);
          fg = false;
          break;
        } else {
          ids.push(it.id);
        }
      }
      if (!fg) return;

      U.qconfim(`确定通知所选定的订单驾驶员？`).then(r => {
        if (r) {
          let loading = U.qloading("请稍后...");
          orderService.noticeDriver({ ids: ids.join(",") }).then((res) => {
            U.qclose(loading);

            if (!res || res.code != 1) {
              U.qerror(res.msg);
            } else {
              U.qsuccess(res.msg);

              // 调用方法-重新加载
              that.getDgList();
            }
          });
        }
      });
    },
    // 显示/隐藏-修改订单车辆-弹框
    setUpdOrderCarMd(e) {
      const that = this, U = that.U, md = that.updOrderCarMd;

      if (!e.state) {
        md.obj = null;
        md.state = false;
      } else {
        let row = e.row;
        if (!row.plateNum) {
          U.qerror('当前订单还未派车');
        } else {
          md.obj = row;
        }
        md.state = true;
      }
    },

    // 显示/隐藏-主驾设置-弹框
    setSetMainDriverMd(e) {
      const that = this, U = that.U, md = that.setMainDriverMd;

      if (!e.state) {
        if (!e.ps) {
          md.state = false;
        } else {// 提交-设置订单主驾
          let ps = {
            // 订单ID
            orderId: md.obj.id,
            // 驾驶员用户名
            driverUname: e.ps.driver.uname,
          };
          logisticsSer.setOrderDriver(ps).then((res) => {
            if (res.code != 1) {
              U.qerror(res.msg);
            } else {
              U.qsuccess(res.msg);

              // 关闭弹框、清空数据、刷新列表
              md.obj = null;
              md.state = false;
              that.getDgList();
            }
          });
        }
      } else {
        let row = e.row;
        if (row.driver) {
          md.obj = { id: row.id, realName: row.driver.split('-')[0], phone: row.driver.split('-')[1] };
        } else {
          md.obj = { id: row.id, realName: '', phone: '' };
        }
        md.state = true;
      }
    },

    // 删除子订单
    delChildOrder() {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length != 1) {
        U.qerror(`您选择了${rows.length}条数据，请选择一条数据`);
      } else {
        let row = rows[0];

        U.qconfim(`确定删除所选订单？`).then(r => {
          if (r) {
            let loading = U.qloading("请稍后...");
            let ps = { orderNum: row.orderNum };
            orderService.delChildOrder(ps).then((res) => {
              U.qclose(loading);

              if (!res || res.code != 1) {
                U.qerror(res.msg);
              } else {
                U.qsuccess(res.msg);

                // 调用方法-重新加载
                that.getDgList();
              }
            });
          }
        });
      }
    },
    // 取消派车
    cancelDisOrder() {
      const that = this, rows = that.getSeledRows();
      if (rows.length == 0) {
        that.U.qerror("请至少选择一条数据");
      } else {
        let ids = [],
          fg = true;
        for (let i = 0; i < rows.length; i++) {
          let row = rows[i];
          if (!row.plateNum) {
            fg = that.U.qerrorFalse(`选中的第${i + 1}条订单：未派车`);
            break;
          } else {
            ids.push(row.id);
          }
        }
        if (!fg) return;

        that.U.qconfim(`确定对所选择的订单取消派车？<span style='color:red'>（如果合并订单已完团，同时会对已完团的合并订单取消派车）</span>`).then(r => {
          if (r) {
            let loading = that.U.qloading("请稍后...");
            let ps = { ids: ids.join(",") }; // 订单号：多个用逗号分隔
            orderService.cancelDisCar(ps).then((res) => {
              that.U.qclose(loading);

              if (!res || res.code != 1) {
                that.U.qerror(res.msg);
              } else {
                that.U.qsuccess(res.msg);

                // 调用方法-重新加载
                that.getDgList();
              }
            });
          }
        });
      }
    },
    /**
     * 打开-付上网费-弹框
     */
    payInternetFeeMd(e) {
      const that = this, rows = that.getSeledRows();

      if (e) {
        if (rows.length != 1) {
          that.U.qerror(`您选择了${rows.length}条数据，请选择一条数据`);
        } else {
          let row = rows[0];

          if (!row.plateNum) {
            that.U.qerror("选中订单[未派车]，不能添加上网费");
          } else {
            that.md.payInternetFee.state = e;
            that.md.payInternetFee.order = row;
          }
        }
      } else {
        that.md.payInternetFee.state = e;
        that.md.payInternetFee.order = null;
      }
    },
    /**
     * 打开-收上网费-弹框
     */
    collectInternetFeeMd(e) {
      const that = this, rows = that.getSeledRows();

      if (e) {
        if (rows.length === 0) {
          that.U.qerror(`您选择了${rows.length}条数据，请选择一条数据`);
        } else {
          let row = rows[0];
          if (!row.plateNum) {
            that.U.qerror("选中订单[未派车]，不能添加上网费");
          } else {
            that.md.collectInternetFee.state = e;
            that.md.collectInternetFee.order = rows;
          }
        }
      } else {
        that.md.collectInternetFee.state = e;
        that.md.collectInternetFee.order = null;
      }
    },
    // 拆分订单-弹框
    splitOrderMd(e) {
      const that = this, U = that.U, md = that.md.splitOrder, rows = that.getSeledRows();

      if (!e.state) {
        // 关闭弹框
        md.state = e.state;
      } else {
        // 打开弹框
        if (rows.length != 1) {
          U.qerror(`您选择了${rows.length}条数据，请选择一条数据`);
        } else {
          let row = rows[0];

          // 找到当前选择数据的原数据订单对象
          let co = that.resDgList.find((o) => { return o.id == row.id; });
          if (!co) {
            that.U.qerror(`选中的订单已不存在，请重新选择！`);
          } else {
            md.state = e.state;
            md.order = that.getFmChildOrder(co);
            // 保存客户姓名和手机号
            md.order.useCarCus = {
              realName: co.carOrderBase.customId.baseUserId.realName,
              phone: co.carOrderBase.customId.baseUserId.phone,
            };
            // 保存-操作员姓名和手机号
            md.order.operatorCus = {
              realName: co.carOrderBase.dutyBaseUser.realName,
              phone: co.carOrderBase.dutyBaseUser.phone,
            };
          }
        }
      }
    },
    /** 设为外调 */
    setOutTransfer() {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length == 0) {
        U.qerror('请至少选择一条数据');
      } else {
        let ids = [], fg = true;
        for (let i = 0; i < rows.length; i++) {
          let row = rows[i];
          if (row.useSelf == 0) {
            fg = U.qerrorFalse(`选中的第${i + 1}条订单已设为外调，请取消该条订单选择！`);
            break;
          } else {
            ids.push(row.id);
          }
        }
        if (!fg) return;

        U.qconfim(`确定将所选子订单<span class="c-red">设为外调</span>？`).then(r => {
          if (r) {
            let loading = U.qloading('提交中，请稍后...');
            let ps = { idList: ids };// 订单id：eg:[1,2]

            orderService.setOutTransfer(ps).then(res => {
              U.qclose(loading);

              if (!res || res.code != 1) {
                U.qerror(res.msg);
              } else {
                U.qsuccess(res.msg);

                // 调用方法-重新加载
                that.getDgList();
              }
            });
          }
        });
      }
    },
    /** 临空时间设置 */
    emptyTimesMd(e) {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (e.state) {// 打开弹框
        if (rows.length != 1) {
          U.qerror('请选择一条订单数据');
        } else {
          let row = rows[0];

          // 找到当前选择数据的原数据订单对象
          let co = that.resDgList.find((o) => { return o.id == row.id; });
          if (co) {
            // 临空设置是针对某一天
            let ps = co.dayMps[0];
            if (!ps) {
              U.qerror('所选订单数据不完整，不能操作此功能，请联系管理员');
              return;
            }

            let posList = [];
            // 加入开始地点
            if (ps.spoint.lngLat) {
              posList.push({
                label: '开始地点',
                options: [{
                  area: `${ps.spoint.city}-${ps.spoint.county}`,
                  address: ps.spoint.address,
                  name: ps.spoint.address.split(' ')[1],
                  lnglat: ps.spoint.lngLat,
                  isSta: ps.spoint.isSta
                }]
              });
            }

            // 加入上午行程地点数组
            if (ps.morningPoint && ps.morningPoint.length > 0) {
              let opts = [];
              ps.morningPoint.forEach(it => {
                opts.push({
                  area: `${it.city}-${it.county}`,
                  address: it.address,
                  name: it.address.split(' ')[1],
                  lnglat: it.lngLat,
                  isSta: it.isSta
                });
              });
              posList.push({ label: '上午行程', options: opts });
            }

            // 加入午餐地点
            if (ps.lunchPoint && ps.lunchPoint.lngLat) {
              posList.push({
                label: '午餐地点',
                options: [{
                  area: `${ps.lunchPoint.city}-${ps.lunchPoint.county}`,
                  address: ps.lunchPoint.address,
                  name: ps.lunchPoint.address.split(' ')[1],
                  lnglat: ps.lunchPoint.lngLat,
                  isSta: ps.lunchPoint.isSta
                }]
              });
            }

            // 加入下午行程地点数组
            if (ps.afternoonPoint && ps.afternoonPoint.length > 0) {
              let opts = [];
              ps.afternoonPoint.forEach(it => {
                opts.push({
                  area: `${it.city}-${it.county}`,
                  address: it.address,
                  name: it.address.split(' ')[1],
                  lnglat: it.lngLat,
                  isSta: it.isSta
                });
              });
              posList.push({ label: '下午行程', options: opts });
            }

            // 加入晚餐地点
            if (ps.dinnerPoint && ps.dinnerPoint.lngLat) {
              posList.push({
                label: '晚餐地点',
                options: [{
                  area: `${ps.dinnerPoint.city}-${ps.dinnerPoint.county}`,
                  address: ps.dinnerPoint.address,
                  name: ps.dinnerPoint.address.split(' ')[1],
                  lnglat: ps.dinnerPoint.lngLat,
                  isSta: ps.dinnerPoint.isSta
                }]
              });
            }

            // 加入结束地点
            if (ps.epoint.lngLat) {
              posList.push({
                label: '结束地点',
                options: [{
                  area: `${ps.epoint.city}-${ps.epoint.county}`,
                  address: ps.epoint.address,
                  name: ps.epoint.address.split(' ')[1],
                  lnglat: ps.epoint.lngLat,
                  isSta: ps.epoint.isSta
                }]
              });
            }

            that.md.emptyTimes = {
              state: true,
              order: co,
              orderNum: row.orderNum,
              dayId: ps.id,
              date: ps.stime.split(' ')[0],
              stime: ps.stime.split(' ')[1].substr(0, 5),
              etime: ps.etime.split(' ')[1].substr(0, 5),
              posList: posList
            };
          }
        }
      } else {// 关闭弹框
        // 设置状态
        that.md.emptyTimes.state = e.state;
      }
    },

    // 显示/隐藏-转顺风车订单-弹框
    setTransferSfcOrderMd(e) {
      const that = this, U = that.U, md = that.transferSfcOrderMd, rows = that.getSeledRows();

      if (!e.state) {
        md.obj = null;
        md.state = false;
      } else {
        if (rows.length != 1) {
          U.qerror(`${rows.length === 0 ? '请' : '只能'}选择一条订单`);
        } else {
          md.obj = rows[0];
          md.state = true;
        }
      }
    },

    /** 取消-转顺风车订单 */
    cancelTransferSfcOrder() {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length != 1) {
        U.qerror(`${rows.length === 0 ? '请' : '只能'}选择一条订单`);
      } else {
        if (!rows[0].freeMark) {
          fg = U.qerrorFalse(`选中的订单不是转顺风车订单，不能操作！`);
        } else {
          U.qconfim(`确定将所选子订单<span class="c-red">恢复成转接订单</span>？`).then(r => {
            if (r) {
              let loading = U.qloading('提交中，请稍后...');
              let ps = { orderNum: rows[0].orderNum };
              orderService.cancelChildToFreeOrder(ps).then(res => {
                U.qclose(loading);

                if (!res || res.code != 1) {
                  U.qerror(res.msg);
                } else {
                  U.qsuccess(res.msg);

                  // 调用方法-重新加载
                  that.getDgList();
                }
              });
            }
          });
        }
      }
    },

    // 查询联盟订单
    queryUnionOrder() {
      const that = this, ps = that.dg.ps;

      ps.unionOrder = ps.unionOrder === 0 ? 1 : 0;
      that.getDgList();
    },

    /**
     * 设置联盟订单
     * @param {Number} t 操作类型 1-设置联盟订单 0-取消设置联盟订单 
     */
    setUnionOrder(t) {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length === 0) {
        U.qerror('请至少选择一条订单');
      } else {
        // 已派车的订单不能取消
        if (t === 0) {
          // 获取已派车的选中订单
          let noStr = rows.filter(it => it.plateNum).map(it => (it.index + 1)).join('、');
          if (noStr) return U.qerrorFalse(`第${noStr}行订单已派车，不能取消！`);
        }

        let ps = {
          ids: rows.map(it => it.id).join(','),
          setValue: t
        };
        orderService.setUnionOrder(ps).then(res => {
          if (!res || res.code != 1) {
            U.qerror(res.msg);
          } else {
            U.qsuccess(res.msg);

            // 调用方法-重新加载
            that.getDgList();
          }
        });
      }
    },
    // 合并订单
    mergeOrdersFlag(t) {
      const that = this, U = that.U, rows = that.getSeledRows();
      console.log(rows, '11')

      if (t == 0) {
        // t == 0取消合并标记
        if (rows.length != 1) {
          U.qerror('只能选择一条订单');
        } else (
          U.qconfim(`确定取消所选合并订单？`).then(r => {
            if (r) {
              let loading = U.qloading("请稍后...");
              let ps = {
                ids: rows[0].id,
                setValue: t,
              };
              orderService.mergeOrdersFlag(ps).then((res) => {
                U.qclose(loading);

                if (!res || res.code != 1) {
                  U.qerror(res.msg);
                } else {
                  U.qsuccess(res.msg);

                  // 调用方法-重新加载
                  that.getDgList();
                }
              });
            }
          })
        )

      } else if (t == 1) {
        // t == 1合并标记
        if (rows.length <= 1) {
          U.qerror('请至少选择两条订单');
        } else (
          U.qconfim(`确定合并所选订单？`).then(r => {
            if (r) {
              let loading = U.qloading("请稍后...");
              let ps = {
                ids: rows.map(it => it.id).join(','),
                setValue: t,
              };
              orderService.mergeOrdersFlag(ps).then((res) => {
                U.qclose(loading);
                if (!res || res.code != 1) {
                  U.qerror(res.msg);
                } else {
                  U.qsuccess(res.msg);

                  // 调用方法-重新加载
                  that.getDgList();
                }
              });
            }
          })
        )
      }

    },
    //#region 代收二维码
    QRcodeBtn() {
      const that = this, U = that.U, rows = that.getSeledRows();

      if (rows.length < 1 || rows.length > 1) {
        U.qerror('必须选择一条订单');
      } else {
        that.QRcode = true
        that.dg.ps.imgUrl = rows[0].helpGathUrl
        that.dg.ps.helpGathPrice = rows[0].helpGathPrice

        console.log(that.dg.ps.imgUrl)
      }

    },
    addQRcodeBtn() {
      const that = this, U = that.U, rows = that.getSeledRows();

      let ps = {
        ids: rows.map(it => it.id).join(','),
        helpGathUrl: that.dg.ps.imgUrl,
        helpGathPrice: that.dg.ps.helpGathPrice,

      };
      if (ps.helpGathUrl) {
        if (ps.helpGathPrice == 0 || ps.helpGathPrice == '') {
          return Message.warning("请输入代收金额！");

        }

      }

      let loading = U.qloading("请稍后...");
      orderService.setHelpGathUrl(ps).then((res) => {
        U.qclose(loading);
        if (!res || res.code != 1) {
          U.qerror(res.msg);
        } else {
          U.qsuccess(res.msg);
          that.QRcode = false
          // 调用方法-重新加载
          that.getDgList();
        }
      });


    }
    //#endregion
  },
};
</script>

<style lang="less" scoped>
.el-textarea__inner {
  width: 400px !important;
  min-height: 300px !important;
}

.el-icon-plus {

  line-height: 280px !important;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}

.dis-order-list ::v-deep {
  .el-table__row:hover {
    color: #666 !important;
  }

  // 隐藏全选
  // .el-table__header .el-checkbox__input{display: none;}
}
</style>
